package csw;

import java.util.Scanner;

public class Reserve{
	public Reserve(){
		
	}
	
	public void printMenu(){
		System.out.println("예약(1),조회(2),취소(3),끝내기(4)>>");
		
	}
	public void reserve(){
}

	public static void main(String[] args) {
		Reserve r = new Reserve();
		Theater t = new Theater();
		int choice = -1;
		Scanner sc = new Scanner(System.in);
		
		while(true){
			r.printMenu();
			
			try{
				choice = Integer.parseInt(sc.nextLine());
				
				if(choice<1||choice>4)
					throw new Exception();
			}catch(Exception e) {
				System.out.println("잘못선택");
				continue;
			}
			switch(choice){
			case 1:
				System.out.println("좌석구분S(1),A(2),B(3)>>");
				try{
					choice = Integer.parseInt(sc.nextLine());
				}catch(Exception e){
					System.out.println("잘못선택");
					continue;
				}
				t.printSeat(choice-1);
				
				System.out.println("이름>>");
				String name = sc.nextLine();
				System.out.println("번호>>");
				int seatNumber = Integer.parseInt(sc.nextLine());
						
						if(seatNumber < 1||seatNumber>10){
							System.out.println("잘못선택");
							continue;
						}
						
						if(t.reserve(choice-1,seatNumber-1,name)){
							System.out.println("<<예약을 완료하였습니다.>>");
						}else{
							System.out.println("이미 예약된 좌석입니다.>>");
						}
						
						break;
				case 2:
				t.printAllSeats();
				System.out.println("<<<조회를 완료하였습니다.>>>");
				break;
				case 3:
					System.out.println("(좌석구분 S(1),A(2),B(3)>>");
					try{
						choice = Integer.parseInt(sc.nextLine());
					}catch(Exception e) {
						System.out.println("잘못선택");
						continue;
					}
					
					t.printSeat(choice-1);
					
					System.out.println("이름>>");
					name = sc.nextLine();
					
					if(t.cancel(choice-1,name)){
						System.out.println("<<예약을 취소했습니다.<>>");
					}else{
						System.out.println("<<예약 취소에 실패 했습니다.>>");
					}
					break;
				case 4:
					return;
				}
				}
				}
	
			}
		
			class Theater {
				public static final int SEATS = 0;
				public static final int SEATA = 1;
				public static final int SEATB = 2;
		
				String [][]seats = new String[3][10];
				
				public Theater(){
					for(int i=0;i<3;i++){
						for(int j=0;j<10;j++){
							seats[i][j]= "---";
						}
					}
				}
				
				public boolean reserve(int gubun,int number,String name){
					if( seats[gubun][number].equals("---")){
						seats[gubun][number]=name;
						return true;
					}else{
						return false;
					}
				}
				
				public boolean cancel(int gubun,String name){
					for(int j=0;j<10;j++){
						if(seats[gubun][j].equals(name)){
							seats[gubun][j] = "---";
							return true;
						}
					}
					
					return false;
				}
				
				public void printSeat(int gubun){
					System.out.println((gubun+1) + ">>");
					for(int i=0;i<10;i++){
						System.out.println(seats[gubun][i] + " ");
					}
					
					System.out.println();
				}
				
				public void printAllSeats() {
					printSeat(SEATS);
					printSeat(SEATS);
					printSeat(SEATS);
					
					
					
		
		
	}//main

}//class
